home *** CD-ROM | disk | FTP | other *** search
/ The Trig Explorer / The Trig Explorer.iso / mac / Explorer / inverse.dxr / 00075_Invers Sine.ls < prev    next >
Encoding:
Text File  |  1998-07-22  |  3.2 KB  |  95 lines

  1. on mouseDown me
  2.   set xCenter to ((the left of sprite 4 + the right of sprite 4) / 2) + 1
  3.   set yCenter to ((the top of sprite 4 + the bottom of sprite 4) / 2) + 2
  4.   set radius to the width of sprite 4 / 2
  5.   set the cursor of sprite the spriteNum of me to [member "Closed Hand", member "Closed Hand Mask"]
  6.   repeat while the stillDown
  7.     set mx to the mouseH
  8.     set my to the mouseV
  9.     set xAtMouse to mx - xCenter
  10.     set yAtMouse to my - yCenter
  11.     if xAtMouse <> 0 then
  12.       set angleAtMouse to atan(float(abs(yAtMouse)) / float(abs(xAtMouse)))
  13.       if angleAtMouse = 0 then
  14.         set yAtCircle to 0
  15.         set xAtCircle to radius * (xAtMouse / abs(xAtMouse))
  16.       else
  17.         set yAtCircle to sin(angleAtMouse) * float(radius) * (yAtMouse / abs(yAtMouse))
  18.         set xAtCircle to cos(angleAtMouse) * float(radius) * (xAtMouse / abs(xAtMouse))
  19.       end if
  20.     else
  21.       set xAtCircle to 0
  22.       if yAtMouse <> 0 then
  23.         set yAtCircle to radius * (yAtMouse / abs(yAtMouse))
  24.       else
  25.         set yAtCircle to radius
  26.       end if
  27.     end if
  28.     set the locH of sprite the clickOn to xCenter + xAtCircle
  29.     set the locV of sprite the clickOn to yCenter + yAtCircle
  30.     drawLine(6, yCenter, xCenter, the locV of sprite the clickOn, the locH of sprite the clickOn)
  31.     set dy to float(yCenter - the locV of sprite the clickOn)
  32.     set dy to -dy
  33.     set dx to float(xCenter - the locH of sprite the clickOn)
  34.     if dx = 0 then
  35.       if dy < 0 then
  36.         set theta1 to float(1.5 * PI)
  37.       else
  38.         set theta1 to float(PI / 2.0)
  39.       end if
  40.     else
  41.       if dx > 0 then
  42.         set theta1 to float(atan(float(dy / dx)))
  43.         if theta1 < 0 then
  44.           set theta1 to float(theta1) + (2.0 * PI)
  45.         end if
  46.       else
  47.         set theta1 to float(atan(float(dy / dx))) + PI
  48.       end if
  49.     end if
  50.     set the floatPrecision to 2
  51.     if theta1 > PI then
  52.       set theta1 to theta1 - PI
  53.     else
  54.       set theta1 to theta1 + PI
  55.     end if
  56.     set temp to theta1 * 180.0 / PI
  57.     if temp = 360.0 then
  58.       put "0.0" into field "theta"
  59.     else
  60.       put temp into field "theta"
  61.     end if
  62.     if dx <> 0 then
  63.       put float(field "R") * float(cos(theta1)) into field "X1"
  64.     else
  65.       put "0.0" into field "X1"
  66.     end if
  67.     if (field "theta" > 90) and (field "theta" <= 270) then
  68.       put 180.0 - field "theta" into field "theta"
  69.     end if
  70.     if (field "theta" > 270) and (field "theta" < 360) then
  71.       put -(360.0 - field "theta") into field "theta"
  72.     end if
  73.     put float(field "R") * float(sin(theta1)) into field "Y1"
  74.     put "(" & field "X1" & "," & field "Y1" & ")" into field "x-y"
  75.     put float(field "Y1" / field "R") into field "YR"
  76.     put PI / 180.0 * field "theta" & " rad." into field "Rad"
  77.     put field "theta" & "deg" into field "thetaD"
  78.     updateStage()
  79.   end repeat
  80.   set the cursor of sprite the spriteNum of me to [member "Hand", member "Hand Mask"]
  81. end
  82.  
  83. on beginSprite me
  84.   set the cursor of sprite the spriteNum of me to [member "Hand", member "Hand Mask"]
  85.   put "2" into field "R"
  86.   put "(1.88, 0.67)" into field "x-y"
  87.   put "0.34" into field "YR"
  88.   put "0.34 rad." into field "Rad"
  89.   put "19.70" & "deg" into field "thetaD"
  90. end
  91.  
  92. on endSprite me
  93.   set the cursor of sprite the spriteNum of me to 0
  94. end
  95.